package face.pay.web.device.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import face.pay.constant.UserType;
import face.pay.dao.DeviceAssignmentInfoDao;
import face.pay.entity.DeviceAssignmentInfo;
import face.pay.entity.DeviceOrderInfo;
import face.pay.entity.UserInfo;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.web.device.service.DeviceAssignmentInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname DeviceAssignmentInfoServiceImpl
 * @Description JJL
 * @Date 2019/11/13 17:23
 */
@Service
@Slf4j
public class DeviceAssignmentInfoServiceImpl implements DeviceAssignmentInfoService {

    @Autowired
    private DeviceAssignmentInfoDao deviceAssignmentInfoDao;

    /**
     * 转出设备
     *
     * @param deviceAssignmentInfo
     */
    @Override
    public ResultMessage addDeviceAssignmentInfo(DeviceAssignmentInfo deviceAssignmentInfo) {
        deviceAssignmentInfoDao.insert(deviceAssignmentInfo);
        return ResultMessage.createSuccess();
    }

    @Override
    public PageData queryPage(UserInfo loginUser, PageParam pageParam, DeviceAssignmentInfo deviceAssignmentInfo) {

        PageHelper.startPage(pageParam.getPageNo(),pageParam.getPageSize());

        deviceAssignmentInfo.setOemId(loginUser.getOemId());
        deviceAssignmentInfo.setGiveUserId(loginUser.getId());

        List<DeviceAssignmentInfo> deviceAssignmentInfos = this.deviceAssignmentInfoDao.queryList(deviceAssignmentInfo);

        PageInfo<DeviceAssignmentInfo> pageInfo = new PageInfo <>(deviceAssignmentInfos);

        PageData<DeviceAssignmentInfo> pageData = new PageData<>(pageInfo.getTotal(),deviceAssignmentInfos);

        return pageData;
    }
}
